package com.itheima.mapper;

import com.itheima.domain.Category;
import com.itheima.domain.Route;
import com.itheima.domain.RouteImg;
import com.itheima.domain.Seller;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface RouteMapper {

    /**
     * 根据id查询线路
     * @param cid
     * @return
     */

    @Select("SELECT * FROM tab_route WHERE cid = #{cid}")
    List<Route> routeFindByCid(int cid);


    /**
     * 根据id查看线路的详细信息
     * @param rid
     * @return
     */
    @Results(
            value = {
                    @Result(column = "rid" , property ="rid" ),
                    @Result(column = "rname" , property ="rname" ),
                    @Result(column = "price" , property ="price" ),
                    @Result(column = "description" , property ="description" ),
                    @Result(column = "num" , property ="num" ),
                    @Result(column = "cid" , property ="cid" ),
                    @Result(column = "rimage" , property ="rimage" ),
                    @Result(column = "sid" , property ="sid" ),

                    @Result(column = "cid" , property ="category" , one = @One(select = "findCategoryByCid")),
                    @Result(column = "sid" , property ="seller" ,one = @One(select = "findSellerBySid")),
                    @Result(column = "rid" , property ="routeImgList" ,many = @Many(select = "findRouteImgListByRid"))
            }
    )

    @Select("SELECT * FROM tab_route WHERE rid = #{rid}")
    Route findRouteByRid(int rid);

    @Select("SELECT * FROM tab_category WHERE cid = #{cid}")
    Category findCategoryByCid(Integer cid);

    @Select("SELECT * FROM tab_seller WHERE sid = #{sid}")
    Seller findSellerBySid(Integer sid);

    @Select("SELECT * FROM tab_route_img WHERE rid = #{rid}")
   List<RouteImg> findRouteImgListByRid(Integer rid);


}
